NAMES=$(shell find ./ -name "??*" -type d|sed "s/\.\///g")
BlackS=
SPACE:=$(BlackS)
AR				:=ar
AFlag 				:=cr
ALL_OBJS			:=
# linear_list
TARS:=$(filter-out general.so,$(patsubst %,%.so,$(NAMES)))
# linear_list.so
DTAR:=$(addprefix ../bin/,$(TARS))
# ../bin/linear_list.so
ARCH_TAR			:=../lib/libgeneral.a
vpath %.a ../lib

inc				=../inc
INC				:=-I$(inc)


.SUFFIXES:
.SUFFIXES:.c .o .a .so
.PHONY:all MSG ARCH_LIB

include ./general/Makefile
ALL_OBJS+=$(addprefix ./general/,$(obj_general))

ifeq ($(MAKELEVEL),1)
all:$(ARCH_TAR) $(DTAR)
else
all:MSG
endif

define DIRS_template

include $(addsuffix Makefile,./$(basename $(notdir $(1)))/)
$(1):$$(patsubst %,./$(basename $(notdir $(1)))/%,$$(obj_$(basename $(notdir $(1)))))
ALL_OBJS+=$$(patsubst %,./$(basename $(notdir $(1)))/%,$$(obj_$(basename $(notdir $(1)))))

endef


$(foreach sdir,$(DTAR),$(eval $(call DIRS_template,$(sdir))))

$(ARCH_TAR):$(addprefix ./general/,$(obj_general))
	$(AR) $(AFlag) -o $@ $^ 


$(DTAR):LFlag+=-L../lib -lgeneral
$(DTAR):
	$(CC) $(DFlag) $(LFlag) -o $@ $^ $(ARCH_TAR) 

$(ALL_OBJS):%.o:%.c
	$(CC) $(CFlag) $(INC) -o $@ $<

MSG:
	-@echo "Second level sub Makefile, please check make levels."
	-@echo "MAKELEVEL = " $(MAKELEVEL)", " "but 1 required."

clean:
	-rm -f $(DTAR) $(ALL_OBJS) $(ARCH_TAR)

.INTERMEDIATE:$(ALL_OBJS)
